#pragma once

#include "HTimer.h"
#include "HTimerRunner.h"

namespace timer {

template<class TString = std::wstring>
class HTimerManager {

public:
	HTimerManager()
		: index_(0)
		, timer_runner_(NULL) { }

public:
	inline bool initialize(const typename HTimerRunner<TString>::HListenRunner& _listen_runner, const typename HTimerRunner<TString>::HTaskRunner& _task_runner) {
		timer_runner_ = HTimerRunner<TString>::new_instance(_listen_runner, _task_runner);
		return true;
	}
	inline void uninitliaze() {
		HTimerRunner<TString>::delete_instance(timer_runner_);
		timer_runner_ = NULL;
	}

	inline HTimer<TString> timer() {
		return HTimer<TString>(index_.fetch_add(1), timer_runner_);
	}

private:
	base::eec::atomic_int index_;
	base::eec::shared_ptr<HTimerRunner<TString>> timer_runner_;
};

} // namespace timer
